<?php
/**
 * ============================================================================
 * Doxt Version: 1.0           杭州多讯科技有限公司
 * Web: http://www.doxt.com
 * Copyright (C) 2007 - 2010 Doxt Technology Inc., All Rights Reserved.
 * ---------------------------------------------
 * $Date: 2008.4.8
*/
  include_once("./config.php");
  $tpl = new PhplibTpl($conf["admin_tpl_path"]);
  if (! empty($_GET['mode']) )
  {   
    include($conf["include_path"] . $_GET['mode'] . ".php");
  }
  //分类列表文件
  include($conf["include_path"] . "list_cate.php");  
  $tpl -> set_file("main", "news.htm");
  $tpl -> set_block("main", "NEWS_LIST", "news_list");
  $tpl -> set_block("main","TYPE_LIST","type_list");
  $new_cate_id =$_POST['s_cate'];
  $tmp_str ="";
  //get_News_Sub( $tmp_str, 0 );      //该顶级分类下的所有子类
  $tmp_str = substr($tmp_str, 1, strlen($tmp_str));   
  $query = "SELECT * FROM $TBL_NEWS WHERE cate_id = 0 and state=2 ";   //没有文章
  

  //用户按下了"查找"  
  $btn_sub = $_POST["btn_sub2"]; 
  if ($btn_sub)
  {    
	$search_key = work_str( $_POST["search_key"] );  //查找关键字
	if (! empty($search_key))
	{
	  $search_str = " and (`ch_headline` like '%" . $search_key . "%')";
      $query .= $search_str;
	} //End if	 	
  } 
  $query_footer = " order by id DESC";
  $query = $query . $query_footer;
  //实现分页
  include( $conf['base_path'] . "lib/make_pages.php");
  $cur_page = (int)$_GET["p"];   //获取当前页
  $url_param = preg_replace("/(p=[0-9]+)&/", "", $_SERVER['QUERY_STRING']);
  $pages = new Pager($query, $cur_page, 20, $url_param);
  $page_string = $pages -> getPageString();   
  $res = $pages -> getRsPerPage();
  while ($rows = mysql_fetch_array($res))
  {
    $news_id = $rows["id"];
	if($rows['img']!='')
    {
		$file ='../../upload/news/'.$news_id."/homeimage/".$rows['img'];
		$img = "<img src='$file' width='100'/><br>";
    } 

    $edit_url = "?mode=edit_news&id=" . $news_id;
    $del_url = "?mode=del_news&del_id=". $news_id;
	$tpl -> set_var(array(
						"CATE_TITLE" => $array['zh_cate_title'],
						"parent_id"=>$array['parent_id'],
						"cate_id"=>$array['cate_id'],
						"NEWS_ID" => $news_id,
						"EDIT_URL" => $edit_url,
						"DEL_URL" => $del_url,
						"PAR_TITLE"=>$array1['zh_cate_title'],
						"ch_headline" => $rows["ch_headline"],
						"en_headline" => $rows['en_headline'],
						"date_added" =>$rows["date_added"],
						"user_id" => $rows['user_id'],
						"ch_source" => $rows['ch_source'],
						"ch_text" =>FSubstr(str_replace("&nbsp;","",strip_tags($rows['ch_text'])),0,70),
						"img" =>$img,
		                ));
	$tpl -> parse("news_list", "NEWS_LIST", true);
  } //End while
  if (empty($page_string))
    $page_string = "此條件下暫無文章";
  $tpl -> set_var(array(
                        "SEARCH_KEY" => $search_key,
                        "SHOW_CATE" => $show_cate,
						"INIT_CATE" => $init_cate,
                        "PAGE_STRING" => $page_string
                      ));
  $tpl-> set_var( $conf);
  $tpl -> parse("Output", "main");
  $tpl -> p("Output");
  ?>